<?php

namespace app\common\model;

use think\Model;


class Message extends Model
{

    

    

    // 表名
    protected $name = 'message';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    public function getImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image']) ? $data['image'] : '');
//        $value=explode(',',$value);
//        foreach ($value as $k=>&$v){
//            $v=get_app_image_url($v);
//        }
        $value = get_app_image_url($value);
        return $value;
    }
    /**
     * 消息推送
     * */
    public static function message($user_id=0,$title,$desc,$content='',$status=0){
        $data['user_id'] = $user_id;
        $data['title']   = $title;
        $data['desc']    = $desc;
        $data['content'] = $content;
        $data['status']  = $status;
        return self::create($data);
    }

    /**
     * 订单发货
     * */
    public static function getAdd($order){

        $ordergoods = OrderGoods::where('order_id','in',$order['id'])->select();
        $data['user_id'] = $order['user_id'];
        $data['title'] = '订单发货';
        $data['image'] = $ordergoods[0]['images'];
//        $data['title'] = $ordergoods[0]['goods_name'];
        $data['desc'] = '商品'.$ordergoods[0]['goods_name'].'发货';
        $data['order_id'] = $order['id'];
        $data['status'] = 1;
        $data['createtime'] = time();
        $data['content']    = $data['title'];
        $info = self::create($data);
        return $info;
    }

    /*
     * 商品下单
     * 卖家获取消息
     * */
    public static function getOrderAdd($order){
        $ordergoods = OrderGoods::where('order_id','in',$order['id'])->select();
        $data['user_id'] = $order['sell_id'];
        $data['title'] = '商品下单';
        $data['image'] = $ordergoods[0]['images'];
//        $data['title'] = $ordergoods[0]['goods_name'];
        $data['desc'] = '商品'.$ordergoods[0]['goods_name'].'下单';
//        $data['order_id'] = $order['id'];
        $data['status'] = 1;
        $data['createtime'] = time();
        $data['content']    = $data['title'];
        $info = self::create($data);
        return $info;
    }







}
